﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using devtm.Editor.TypeSelector.AttributeBuilder;
using System.Xml.Linq;

namespace devtm.Editor.TypeSelector
{
    /// <summary>
    /// Interaction logic for WindowBuildAttribute.xaml
    /// </summary>
    public partial class WindowBuildAttribute : Window, IDisposable
    {
        private bool disposed;


        public WindowBuildAttribute()
        {
            InitializeComponent();

        }

        public ContextAttributeBuilder Context
        {
            get { return (ContextAttributeBuilder)objectViewer1.DataContext; }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }



        public System.Xml.Linq.XElement Serialize()
        {
            return objectViewer1.Serialize();
        }


        public void UnSerialize(System.Xml.Linq.XElement node)
        {
            objectViewer1.UnSerialize(node);
        }


        public void UnSerialize(string node)
        {
            try
            {
                XElement nde = XElement.Parse(node);
                objectViewer1.UnSerialize(nde);
            }
            catch (Exception)
            {

            }
        }


        public bool SelectType<T>(T attribute)
            where T : Attribute
        {
            return objectViewer1.SelectType(attribute);
        }


        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }


        public void Dispose(bool disposing)
        {

            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    GC.SuppressFinalize(Context);
                }

                // Note disposing has been done.
                disposed = true;

            }

        }


        ~WindowBuildAttribute()
        {
            Dispose(true);
        }
    }
}
